#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_drf.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include <uf_part.h>

void ufusr(char *x, int *y, int z)
{
        volatile int          ifail;
        int                   mpi_array[100];
        double                mpr_array[70];
        char                  rad_symbol[27], dia_symbol[27];
        tag_t                 part_tag = NULL_TAG,
                          dimension_tag = NULL_TAG;
        int                   i;
        FILE                  *file1,*file2;

      
        ifail = UF_initialize();
        if( !ifail )
        {
                part_tag = UF_PART_ask_display_part();
               /* cycle for dimensions */
                ifail = UF_OBJ_cycle_objs_in_part( part_tag,UF_dimension_type, &dimension_tag );
                file1 = fopen("5521_bef.dat","w+");
                file2 = fopen("5521_aft.dat","w+");
                /* find dimension creation parameters */
                UF_DRF_ask_preferences(mpi_array, mpr_array,rad_symbol, dia_symbol );
                for(i=0;i <=99;i++)
                {
                        fprintf(file1," mpi[%d] = %d", i, mpi_array[i]);
                        if( i % 3 == 0)
                        {
                            fprintf(file1,"\n");
                        }
                }
                for(i=0;i <=51;i++)
                {
                        fprintf(file1," mpr[%d] = %f", i, mpr_array[i]);
                        if( i % 3 == 0)
                        {
                             fprintf(file1,"\n");
                        }
                }
                fprintf(file1,"\n");
                fprintf(file1," rad_val = %s, dia_val = %s\n",rad_symbol,dia_symbol);
                fprintf(file1,"\n");
                mpi_array[6] = 4; /* Set Tolerance type */
                mpi_array[12] = 2; /* Set Tolerance site */
                mpr_array[24] = 0.02;  /* Set Upper Tolerance */
                mpr_array[25] = 0.02;   /* Set Lower Tolerance */


                UF_DRF_set_preferences( mpi_array, mpr_array,
                                rad_symbol, dia_symbol );
                UF_DRF_ask_preferences(mpi_array, mpr_array,
                                  rad_symbol, dia_symbol );
                for(i=0;i <=99;i++)
                {
                        fprintf(file2," mpi[%d] = %d", i, mpi_array[i]);
                        if( i % 3 == 0)
                        {
                                fprintf(file2,"\n");
                        }
                }
                for(i=0;i <=51;i++)
                {
                        fprintf(file2," mpr[%d] = %f", i, mpr_array[i]);
                        if( i % 3 == 0)
                        {
                                fprintf(file2,"\n");
                        }
                }
                fprintf(file2,"\n");
                fprintf(file2,"rad_val = %s, dia_val = %s\n",
                                                        rad_symbol,dia_symbol);
                fprintf(file2,"\n");

        UF_terminate();
        } /* end of success of UF_initialize */
        else
        {

        printf( "Error Initializing. Exiting...\n" );
        }
fclose(file1);
fclose(file2);
}

